package com.fit.WatchShop.pages;

import java.util.LinkedList;

import org.apache.tapestry5.annotations.*;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.beaneditor.Validate;

import com.fit.WatchShop.beans.WatchBean;
import com.fit.WatchShop.interfaces.Buy;
import com.fit.WatchShop.interfaces.User;
import com.fit.WatchShop.interfaces.Watch;
import com.fit.WatchShop.service.Watches;

public class EntryWatch {
	
	@Property
	@Persist
	private Watch watch;
	
	@Inject
	private Watches watches;
	
	@SetupRender
	public void createObject() {
		watch = new WatchBean();
		watch.setBuy(new LinkedList<Buy>());
	}
	
	void onSuccess() {
		watches.save(watch);
	}
	@SessionState
	private User user;

	private boolean userExists;
	
	public User getUser() {
		return user;
	}
	
	Object onActivate() {
		if (!userExists) return Login.class;
		return null;
	}
	
//	private String watchType = "Type of watch: ";
//	private String watchModel = "Model of watch: ";
//	private String watchShortDescription = "Short description watch: ";
//	
//	@InjectPage
//	private ViewWatch viewWatch;
//	
//	@InjectPage
//	private Error errorPage;
//	
//	@OnEvent (value="submit", component="watchInputForm")
//	Object onFromSubmit() {
//		Watch watchW = new WatchBean();
//		watchW.setBuy(new LinkedList<Buy>());
//		watchW.setType(watchType);
//		watchW.setModel(watchModel);
//		watchW.setShortDescription(watchShortDescription);
//		if (watchW.getType()==null || watchW.getModel()==null) {
//            errorPage.setError("Nije moguce dodati novi sat!");
//            return errorPage;
//	}
//		viewWatch.setSingleWatch(watchW);
//        return viewWatch;
//        }
//
//
//	public String getWatchType() {
//		return watchType;
//	}
//	
//	public void setWatchType(String watchType) {
//		this.watchType = watchType;
//	}
//
//	public String getWatchModel() {
//		return watchModel;
//	}
//
//	public void setWatchModel(String watchModel) {
//		this.watchModel = watchModel;
//	}
//
//	public String getWatchShortDescription() {
//		return watchShortDescription;
//	}
//
//	public void setWatchShortDescription(String watchShortDescription) {
//		this.watchShortDescription = watchShortDescription;
//	}

}
